package com.chenyaowei.web.controller.order;

import com.chenyaowei.common.annotation.Log;
import com.chenyaowei.common.annotation.RepeatSubmit;
import com.chenyaowei.common.core.controller.BaseController;
import com.chenyaowei.common.core.domain.AjaxResult;
import com.chenyaowei.common.core.page.TableDataInfo;
import com.chenyaowei.common.enums.BusinessType;
import com.chenyaowei.common.utils.poi.ExcelUtil;
import com.chenyaowei.order.domain.CywOrderItem;
import com.chenyaowei.order.request.OrderCommentReplyRequest;
import com.chenyaowei.order.request.OrderCommentRequest;
import com.chenyaowei.order.service.ICywOrderItemService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 订单项信息Controller
 *
 * @author 陈耀威
 * @date 2023-12-03
 */
@RestController
@RequestMapping("/order/item")
public class CywOrderItemController extends BaseController
{
    @Autowired
    private ICywOrderItemService cywOrderItemService;

    @RepeatSubmit
    @PostMapping("/commentReply")
    public AjaxResult addCommentReply(@RequestBody OrderCommentReplyRequest orderCommentReplyRequest)
    {
        return toAjax(cywOrderItemService.addCommentReply(orderCommentReplyRequest));
    }

    @RepeatSubmit
    @PostMapping("/comment")
    public AjaxResult addComment(@RequestBody OrderCommentRequest orderCommentRequest)
    {
        return cywOrderItemService.addComment(orderCommentRequest);
    }

    /**
     * 查询订单项信息列表
     */
    @PreAuthorize("@ss.hasPermi('order:orderItem:list')")
    @GetMapping("/list")
    public TableDataInfo list(CywOrderItem cywOrderItem)
    {
        startPage();
        List<CywOrderItem> list = cywOrderItemService.selectCywOrderItemList(cywOrderItem);
        return getDataTable(list);
    }

    /**
     * 导出订单项信息列表
     */
    @PreAuthorize("@ss.hasPermi('order:orderItem:export')")
    @Log(title = "订单项信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CywOrderItem cywOrderItem)
    {
        List<CywOrderItem> list = cywOrderItemService.selectCywOrderItemList(cywOrderItem);
        ExcelUtil<CywOrderItem> util = new ExcelUtil<CywOrderItem>(CywOrderItem.class);
        util.exportExcel(response, list, "订单项信息数据");
    }

    /**
     * 获取订单项信息详细信息
     */
//    @PreAuthorize("@ss.hasPermi('order:orderItem:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(cywOrderItemService.selectCywOrderItemById(id));
    }

    /**
     * 新增订单项信息
     */
    @PreAuthorize("@ss.hasPermi('order:orderItem:add')")
    @Log(title = "订单项信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CywOrderItem cywOrderItem)
    {
        return toAjax(cywOrderItemService.insertCywOrderItem(cywOrderItem));
    }

    /**
     * 修改订单项信息
     */
    @PreAuthorize("@ss.hasPermi('order:orderItem:edit')")
    @Log(title = "订单项信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CywOrderItem cywOrderItem)
    {
        return toAjax(cywOrderItemService.updateCywOrderItem(cywOrderItem));
    }

    /**
     * 删除订单项信息
     */
    @PreAuthorize("@ss.hasPermi('order:orderItem:remove')")
    @Log(title = "订单项信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(cywOrderItemService.deleteCywOrderItemByIds(ids));
    }
}
